package com.yoooya.base.admin.controller.call;

import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yoooya.base.admin.controller.AbstractController;
import com.yoooya.base.commons.CommonUtils;
import com.yoooya.base.model.po.call.CallSeatPo;
import com.yoooya.base.model.qo.call.CallSeatQo;
import com.yoooya.base.model.vo.BaseResp;
import com.yoooya.base.service.call.CallSeatService;
import com.yoooya.base.utils.ResponseUtils;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/call/callSeat")
public class CallSeatController extends AbstractController {
    @Autowired
    private CallSeatService callSeatService;

    private static final Logger logger = LoggerFactory.getLogger(CallSeatController.class);

    @Override
    public String getSelfBasePath() {
        return "/";
    }

    /**
     * 添加记录
     */
    @RequestMapping(value = "add")
    @ResponseBody
    public Object addCallSeat(@ModelAttribute("command") CallSeatPo command) {
        BaseResp resp = new BaseResp();
        try {
            int result= this.callSeatService.insert(command);
        } catch (Exception e) {
              logger.warn("controller Exception: ", e);
            resp.setCode(BaseResp.RC_NOT);
            resp.setSuccess(false);
            resp.setMsg("保存失败！");
        }
        return resp;
    }

    /**
     * 修改记录
     */
    @RequestMapping(value = "modify")
    @ResponseBody
    public Object modifyCallSeat(@ModelAttribute("command") CallSeatPo command) {
        BaseResp resp = new BaseResp();
        try {
            int result= this.callSeatService.updateById(command);
        } catch (Exception e) {
              logger.warn("controller Exception: ", e);
            resp.setCode(BaseResp.RC_NOT);
            resp.setSuccess(false);
            resp.setMsg("修改失败！");
        }
        return resp;
    }

    /**
     * 根据主键删除记录
     */
    @RequestMapping(value = "deleteById")
    @ResponseBody
    public Object deleteById(@ModelAttribute("command") CallSeatQo command) {
        BaseResp resp = new BaseResp();
        try {
            int result= this.callSeatService.deleteById(command.getId());
        } catch (Exception e) {
              logger.warn("controller Exception: ", e);
            resp.setCode(BaseResp.RC_NOT);
            resp.setSuccess(false);
            resp.setMsg("删除失败！");
        }
        return resp;
    }

    /**
     * 根据主键指删除记录
     */
    @RequestMapping(value = "deleteByBatch")
    @ResponseBody
    public Object deleteByBatch() {
        BaseResp resp = new BaseResp();
        try {
            String ids = request.getParameter("ids");
            boolean result= this.callSeatService.deleteByBatch(ids);
        } catch (Exception e) {
              logger.warn("controller Exception: ", e);
            resp.setCode(BaseResp.RC_NOT);
            resp.setSuccess(false);
            resp.setMsg("批量删除失败！");
        }
        return resp;
    }

    /**
     * 根据主键获取记录信息
     */
    @RequestMapping(value = "queryById")
    @ResponseBody
    public Object queryById(@ModelAttribute("command") CallSeatQo command) throws Exception {
        CallSeatPo record = this.callSeatService.queryById(command.getId());
        return record;
    }

    /**
     * 查询记录信息
     */
    @RequestMapping(value = "query")
    @ResponseBody
    public Object query(@ModelAttribute("command") CallSeatQo command) throws Exception {
        if (command == null) {
            command = new CallSeatQo();
        }
        PageList<CallSeatPo> records = (PageList<CallSeatPo>) this.callSeatService.query(command);
        return ResponseUtils.paginationResp(records);
    }

    /**
     * 获取所有记录信息
     */
    @RequestMapping(value = "queryByAll")
    @ResponseBody
    public Object queryByAll(@ModelAttribute("command") CallSeatQo command) throws Exception {
        if (command == null) {
            command = new CallSeatQo();
        }
        List<CallSeatPo> records =this.callSeatService.queryByAll(command);
        return records;
    }
}